package com.zmn.oms.model.vo.report;

import com.zmn.common.utils.number.NumberUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 类描述:录单报表VO
 *
 * @author: xuning
 * @since: 2019/4/3 11:06
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ReportOrderedVO implements Serializable {
    /**
     * 录入人部门ID
     */
    Integer deptId;
    /**
     * 录入人ID
     */
    Integer receiverId;
    /**
     * 录入人
     */
    String receiverName;
    /**
     * 总单量
     */
    Integer totalCount;
    /**
     * 总新单
     */
    Integer totalNewCount;
    /**
     * 新单
     */
    Integer newCount;
    /**
     * 返修
     */
    Integer reworkCount;
    /**
     * 新单重复
     */
    Integer newWithDuplicateCount;
    /**
     * 返修重复
     */
    Integer reworkWithDuplicateCount;
    /**
     * 进行中
     */
    Integer doingCount;
    /**
     * 弃单
     */
    Integer discardCount;
    /**
     * 失败
     */
    Integer failCount;
    /**
     * 成功
     */
    Integer successCount;
    /**
     * 弃单率
     */
    String discardRate;
    /**
     * 失败率
     */
    String failRate;
    /**
     * 成功率
     */
    String successRate;
    /**
     * 应收总额
     */
    Integer totalAmountSum;

    public String getTotalAmountSumStr() {
        return new BigDecimal(totalAmountSum).movePointLeft(2).setScale(2, RoundingMode.HALF_UP).toString();
    }

    public void generateRate() {
        this.discardRate = getRate(discardCount, totalCount);
        this.failRate = getRate(failCount, totalCount);
        this.successRate = getRate(successCount, totalCount);
    }

    /**
     * 获取比率
     *
     * @param molecular
     * @param denominator
     * @return
     */
    private String getRate(Integer molecular, Integer denominator) {
        if (NumberUtil.isNullOrZero(molecular) || NumberUtil.isNullOrZero(denominator)) {
            return "0.00%";
        }
        BigDecimal rate = new BigDecimal(molecular).divide(new BigDecimal(denominator), 4, BigDecimal.ROUND_HALF_UP);
        return rate.movePointRight(2).toString() + "%";
    }
}
